type Selector<TInput, TOutput> = (input: TInput) => TOutput;

// 如果数组为空，则返回 null，否则返回最大值
export function max<TValue>(values: TValue[], selector: Selector<TValue, number>) {
  if (values.length === 0) {
    return null;
  }

  let max: number = selector(values[0]);

  for (let index = 1; index < values.length; index++) {
    const targetValue = selector(values[index]);

    if (targetValue > max) {
      max = targetValue;
    }
  }

  return max;
}
